package com.sb.framework.support;

import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;

import com.sb.framework.exception.PropertyNotFountException;

public class PropertyContext extends PropertyPlaceholderConfigurer {

	private static Map<String, String> propertyMap;

	@Override
	protected void processProperties(ConfigurableListableBeanFactory beanFactoryToProcess, Properties props) throws BeansException {
		super.processProperties( beanFactoryToProcess, props );
		propertyMap = new HashMap<String, String>();
		for (Object key : props.keySet()) {
			String keyStr = key.toString();
			propertyMap.put( keyStr, props.getProperty( keyStr ) );
		}
	}

	public static String getProperty(String key) {
		String value = "";
		try {
			value = propertyMap.get( key );
		} catch (Exception e) {
			throw new PropertyNotFountException();
		}
		return value;
	}
}
